package com.liang.springcloud.controller;

import com.liang.springcloud.pojo.Dept;
import com.liang.springcloud.service.DeptClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author:liangli
 * @Date:2020/11/12 9:45
 */
@RestController
public class DeptConsumerController {

    @Autowired
    private DeptClientService service=null;

    @RequestMapping("/consumer/dept/get/{id}")
    public Dept getDept(@PathVariable("id")Long id){
      return this.service.queryById(id);
    }

    @RequestMapping("/consumer/dept/get/list")
    public List<Dept> findAll(){
        return this.service.queryAll();
    }

    @RequestMapping("/consumer/dept/add")
    public Boolean addDept(Dept dept){
        return this.service.addDept(dept);
    }

    //***************************************************

//    //消费者 不因该有service层
//    //restful 风格  (url,实体map,1类型 .class)
//    @Autowired
//    private RestTemplate restTemplate; //提供多种便捷访问远程http服务的方法 简单的restful服务模板
//
//    //ribbon 我们这里的地址，应该是一个变量，通过服务名来访问
////    private static final String REST_URL_PREFIX="http://localhost:8001";
//    private static final String REST_URL_PREFIX="http://springcloud-provider-dept";
//
//   @RequestMapping("/consumer/dept/get/{id}")
//    public Dept getDept(@PathVariable("id")Long id){
//        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/get/"+id,Dept.class);
//    }
//
//    @RequestMapping("/consumer/dept/get/list")
//    public List<Dept> findAll(){
//        return restTemplate.getForObject(REST_URL_PREFIX+"/dept/list",List.class);
//    }
//
//    @RequestMapping("/consumer/dept/add")
//    public Boolean addDept(Dept dept){
//        return restTemplate.postForObject(REST_URL_PREFIX+"/dept/add",dept,Boolean.class);
//    }
}
